package org.openfidias.jdbase.view;

import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.openfidias.jdbase.controller.DisciplinaBo;
import org.openfidias.jdbase.lang.Choose;
import org.openfidias.jdbase.model.DisciplinaDao;

/**
 *
 * @author atila
 */
public class DisciplinaView {

    private DisciplinaView() {
    }

    public static DisciplinaView getInstance() {
        return DisciplinaViewHolder.INSTANCE;
    }

    private static class DisciplinaViewHolder {
        private static final DisciplinaView INSTANCE = new DisciplinaView();
    }

    public void begin() throws IOException, Exception {
       String option = "";
       while (true) {
          menu();
          System.out.print(Console.bash);
          option = Console.read.nextLine();
          if (Choose.is(".create", option)) {
             // create
             DisciplinaBo.getInstance().create();
          } else if (Choose.isAny(new String[]{"*", ".read_all"}, option)) {
             DisciplinaDao.getInstance().list();
          } else if (Choose.is(".read", option)) {
             DisciplinaBo.getInstance().read();
          } else if (Choose.is(".delete", option)) {
             DisciplinaBo.getInstance().delete();
          } else if (Choose.is(".quit", option)) {
             // end program.
             System.exit(0);
          } else if (Choose.is(".clear", option)) {
             Console.clearConsole();
          } else if (Choose.is(".back", option)) {
             // leave view.
             break;
          } else {
             System.out.println("Opção Inválida.");
          }
       }
    }

    private void menu() {
      StringBuilder builder = new StringBuilder();
      builder.append(StringUtils.center(" View Disciplina ", 60, " · "));
      builder.append("\n\n");
      builder.append("[.create] Criar Disciplina\n");
      builder.append("[.read] Visualizar Disciplina\n");
      builder.append("[.read_all][*] Visualizar Todos as Disciplina\n");
      builder.append("[.delete] Deletar Disciplina\n");
      builder.append("[.quit][.back][.clear]");
      System.out.println(builder.toString());
   }
 }
